//
//  TGOrderMenu.m
//  GroupBuy
//
//  Created by wwj on 15/11/4.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "TGOrderMenu.h"
#import "TGOrderMenuItem.h"

@implementation TGOrderMenu
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [TGDataTool shareDataTool].orderArray;
        for (int index = 0; index < array.count; index++) {
            TGOrderMenuItem *btn = [[TGOrderMenuItem alloc] init];
            btn.model = array[index];
            btn.frame = CGRectMake(index * kBottomMenuItemW, 0, 0, 0);
            [self.scrollerView addSubview:btn];
            [btn addTarget:self action:@selector(onClickItemBtn:) forControlEvents:UIControlEventTouchUpInside];
            
            if (index == 0) {
                btn.selected = YES;
                self.itemBtn = btn;
            }
        }
        self.scrollerView.contentSize = CGSizeMake(kBottomMenuItemW * array.count, 0);
    }
    return self;
}

-(void)onSelectItemBtn:(TGBottomMenuItem *)itemBtn{
    [TGDataTool shareDataTool].currentOrder = [[TGDataTool shareDataTool] getOrderWithName:[itemBtn titleForState:UIControlStateNormal]];
}

@end
